<script type="text/javascript">
    {literal}
        
        function sendAction(action){
            $("#action").val(action);
            $("#submitting").submit();    
        }
        
        $(document).ready(function() {
            $("#fulltext").keyup(function(event){
                if(event.keyCode == 13){
                    setFulltext($('#fulltext').val(),'cash_fulltext')
                }
            });
        });
    {/literal}
</script>
<h2 class="pageTitle">State of cash</h2>
{include $data.pathToError}
<div class="menu-list">
    <div style="float: left">
        Fulltext search: <input id="fulltext" type="text" value="{if $data.currentFulltext != ''}{$data.currentFulltext}{/if}" />&nbsp;&nbsp;
    </div>
    <form action="{$data.root}?input=state_of_cash" method="post" id="submitting" style="float: left">
        <input id="action" name="action" value="" type="hidden" />
        Period:
        <select size="1" name="selectedPeriod" id="period">
            {foreach from=$data.periods item="period" key="i"}
                <option {if $period.period==$data.prefill.today}selected="selected"{/if} value="{$period.period}">{$period.period}{if $period.locked==1}*{/if}</option>
            {/foreach}
        </select>
        <input value="Search" type="button" onclick="filter('period',$('#period').val(),'cash_filter')" />
        {if $smarty.session.user.user_type_id == $smarty.const.USER_TYPE_ADMIN }
            <input value="Lock / Unlock" type="button" onclick="sendAction('lock')" /> * locked
        {/if}
    </form>
    <div style="float: right;">
        <a target="_blank" href="{$data.root}excel.php?table=state_of_cash">
            <img src="{$data.root}images/excel.png" title="export to excel" alt="" height="20" width="20" />
        </a>
    </div>
    <div class="clear"></div>
</div>
{if $data.currentFilter || $data.currentFulltext!=''}
    <div class="menu-list bgDark">
        <b>Current filter:</b> 
        <ul>
            {foreach $data.currentFilter as $filter => $value}
                <li>{$filter} = <i>{$value}</i> [<a href="javascript: cancelFilter('{$filter}','cash_filter')" class="baseLink">Cancel</a>]</li>
            {/foreach}
            {if $data.currentFulltext != ''}
                <li>Fulltext = <i>{$data.currentFulltext}</i> [<a href="javascript: cancelFulltext('cash_fulltext')" class="baseLink">Cancel</a>]</li>
            {/if}
        </ul>
    </div>
{/if}
<table class="list">
    <tr>
        {if $smarty.session.user.profile.userlevel == $smarty.const.USER_TYPE_ADMIN}
            <td colspan="10" style="text-align: right">
            {else}
            <td colspan="7" style="text-align: right">
            {/if}
            <b>My current status:</b> {$data.myTotal}&nbsp;
        </td>
    </tr>
    <tr>
        <th><a href="javascript: order('created','cash_order')">Created {if $data.currentOrder.0=="created"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th><a href="javascript: order('who_added','cash_order')">Who added {if $data.currentOrder.0=="who_added"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th>
            {if $smarty.session.user.profile.userlevel == $smarty.const.USER_TYPE_TECHNIC}
                User
            {else}
                <a href="javascript: order('user','cash_order')">User {if $data.currentOrder.0=="user"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a>
                {/if}
        </th>
        <th><a href="javascript: order('date','cash_order')">Date of move {if $data.currentOrder.0=="date"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th><a href="javascript: order('amount','cash_order')">Amount {if $data.currentOrder.0=="amount"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th><a href="javascript: order('type_of_move','cash_order')">Type of move {if $data.currentOrder.0=="type_of_move"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th><a href="javascript: order('description','cash_order')">Description {if $data.currentOrder.0=="description"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
                {if $smarty.session.user.profile.userlevel == $smarty.const.USER_TYPE_ADMIN}
            <th><a href="javascript: order('s','cash_order')">S {if $data.currentOrder.0=="s"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th></th>
            <th></th>
        {/if}
    </tr>
    {assign var=counter value=1}
    {foreach $data.cashes as $key => $cash}
        {if $counter==1}
            {assign var=bgClass value='bgDark'}
        {else}
            {assign var=bgClass value='bgLight'}
        {/if}
        <tr class="{$bgClass}">
            {if $counter==1}
                {assign var=counter value=2}
            {else}
                {assign var=counter value=1}
            {/if}
            <td><a class="filterLink" href="javascript: filter('created','{$cash.created}','cash_filter')">{$cash.created_format}</a></td>
            <td><a class="filterLink" href="javascript: filter('who_added','{$cash.who_added}','cash_filter')">{$cash.creator_info.name} {$cash.creator_info.surname}</a></td>
            <td>
                {if $smarty.session.user.profile.userlevel == $smarty.const.USER_TYPE_TECHNIC}
                    {$cash.user_info.name} {$cash.user_info.surname}
                {else}
                    <a class="filterLink" href="javascript: filter('user','{$cash.user}','cash_filter')">{$cash.user_info.name} {$cash.user_info.surname}</a>
                {/if}
            </td>
            <td><a class="filterLink" href="javascript: filter('date','{$cash.date}','cash_filter')">{$cash.d_format}</a></td>
            <td><a class="filterLink" href="javascript: filter('amount','{$cash.amount}','cash_filter')">{$cash.amount}</a></td>
            <td><a class="filterLink" href="javascript: filter('type_of_move','{$cash.type_of_move}','cash_filter')">{$cash.type_format.TypPohybu}</a></td>
            <td>{$cash.description}</td>
            {if $smarty.session.user.profile.userlevel == $smarty.const.USER_TYPE_ADMIN}
                <td>
                    <a class="filterLink" href="javascript: filter('s','{$cash.s}','cash_filter')">{if $cash.s==1}Yes{else}No{/if}</a>
                </td>
                <td>
                    {if $cash.locked==0}
                        <a class="filterLink" href="{$data.root}?input=edit_entry&entry={$cash.Id}"><img src="{$data.root}images/edit.png" height="16" width="16" /></a>
                        {else}
                        <img src="{$data.root}images/edit.png" height="16" width="16" title="locked" />
                        <img src="{$data.root}images/locked.png" height="16" width="16" title="locked" />
                    {/if}
                </td>
                <td>
                    {if $cash.locked==0}
                        <a class="filterLink" href="javascript: void(0)" onclick="deleteEntry({$cash.Id})"><img src="{$data.root}images/delete.png" height="16" width="16" /></a>
                        {else}
                        <img src="{$data.root}images/delete.png" height="16" width="16" title="locked" />
                        <img src="{$data.root}images/locked.png" height="16" width="16" title="locked" />
                    {/if}
                </td>
            {/if}
        </tr>
    {/foreach}
    <tr>
        <th></th>
        <th></th>
        <th></th>
        <th>Total:</th>
        <th>{$data.sum}</th>
        <th></th>
        <th></th>
        {if $smarty.session.user.profile.userlevel == $smarty.const.USER_TYPE_ADMIN}
            <th></th>
            <th></th>
            <th></th>
        {/if}
    </tr>
</table>
<div class="menu-list">
    <span class="pager">{$data.pager}</span>
    Records per page
    <select class="pager" size="1" onchange="changeRecordsPerPage(this.value, 'cash_pager')">
        <option {if $smarty.session.cash_pager==100}selected="selected"{/if} value="100">100</option>
        <option {if $smarty.session.cash_pager==500}selected="selected"{/if} value="500">500</option>
        <option {if $smarty.session.cash_pager==1000}selected="selected"{/if} value="1000">1000</option>
        <option {if $smarty.session.cash_pager==10000000}selected="selected"{/if} value="10000000">All</option>
    </select>
    Count: {$data.total_count}
</div>